package com.qianfeng.xinyihezi.xinyihezi.adapter.adapter_meng;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.bean_meng.Goods;

import java.util.List;

/**
 * Created by Administrator on 2016/11/12.
 */

public class MyListViewAdapter extends BaseAdapter {
    private List<Goods> mList;
    private Context mContext;

    public MyListViewAdapter(List<Goods> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(mContext, R.layout.item_listview, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.mTextViewTitle.setText(mList.get(i).title);
        holder.mTextViewLike.setText(mList.get(i).collection_num);
        holder.mTextViewRead.setText(mList.get(i).page_views);
        Glide.with(mContext).load(mList.get(i).image).into(holder.mImageView);
        return view;
    }

    class ViewHolder {
        TextView mTextViewTitle, mTextViewLike, mTextViewRead;
        ImageView mImageView;

        public ViewHolder(View view) {
            mTextViewTitle = (TextView) view.findViewById(R.id.tv_item_listview_title);
            mTextViewLike = (TextView) view.findViewById(R.id.tv_item_listview_like);
            mTextViewRead = (TextView) view.findViewById(R.id.tv_item_listview_read);
            mImageView = (ImageView) view.findViewById(R.id.iv_item_listview);
        }
    }
}
